# -*- coding: utf-8 -*-
'''
   从industry_industry中取出所需的stock_ID表
'''
import logging
from sqlalchemy import Column, String, DateTime, Integer
from baidustock.database import Base, DBBase, DBSession

logger = logging.getLogger(__name__)


class StockIndustryTable(Base, DBBase):
    '''
        表 ``stockindustry`` 的持久化对象
    '''
    __tablename__ = 'stockindustry'

    stock_ID = Column('stockID', String(255), primary_key=True)
    date = Column('date', DateTime)
    industry_name = Column('industryName', String(255))
    region = Column('region', String(255))
    stock_name = Column('stockName', String(255))
    stock_type = Column('stockType', Integer)

    @classmethod
    def get_list(cls):
        '''
            从''stockindustry''表中获取stock_ID_list
        '''
        stock_ID_list = []
        with DBSession() as session:
            query = session.query(cls).all()
            for instance in query:
                stock_ID_list.append(instance.stock_ID)
        return stock_ID_list
